<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery.js"></script>
</head>

<body>
    <div class="box">
        <input type="checkbox" name="" id="fruit"><span>苹果-</span><span>10</span>
        <input type="number" name="shui" min="1" value="1" id="fruit">
    </div>
    <div class="box">
        <input type="checkbox" name="" id="fruit"><span>香蕉-</span><span>16</span>
        <input type="number" name="shui" min="1" value="1" id="fruit">
    </div>
    <div class="box">
        <input type="checkbox" name="" id="fruit"><span>芒果-</span><span>15</span>
        <input type="number" name="shui" min="1" value="1" id="fruit">
    </div>
    <div class="box">
        <input type="checkbox" name="" id="fruit"><span>草莓-</span><span>30</span>
        <input type="number" name="shui" min="1" value="1" id="fruit">
    </div>
    <div class="box">
        <input type="checkbox" name="" id="fruit"><span>菠萝-</span><span>5</span>
        <input type="number" name="shui" min="1" value="1" id="fruit">
    </div>
    <div class="box">
        <input type="checkbox" name="" id="fruit"><span>糖葫芦-</span><span>5</span>
        <input type="number" name="shui" min="1" value="1" id="fruit">
    </div>
    <p>总价：<span></span></p>
    全选<input type="checkbox" id="price">
</body>
<script>
   $(function () {
        $('.box :checkbox,[name="shui"]').change(function () {
            var total = 0
            $('.box :checkbox').each(function(){
                if ($(this).prop('checked')) {
                    var sum = $(this).next().next().html()
                    var num = $(this).next().next().next().val()
                    total += (sum * num)
                }
                $('span:last').html(total)
            }) 
        })
        $('#price').change(function(){
            $('.box :checkbox').prop('checked',$(this).prop('checked'))
            $('.box :checkbox').change()
        })
        
    })
</script>

</html>